package logic

import (
	"context"
	"weiyun-management-system/weirpc/weirpc"

	"weiyun-management-system/api/internal/svc"
	"weiyun-management-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProuctAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProuctAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProuctAddLogic {
	return &ProuctAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProuctAddLogic) ProuctAdd(req *types.ProuctAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.WeiRpc.ProductAdd(l.ctx, &weirpc.ProductAddRequest{
		UserId:       req.UserId,
		ProductName:  req.ProductName,
		ProductPrice: req.ProductPrice,
		ProductImage: req.ProductImage,
		ProductStock: req.ProductStock,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "成功",
		Data:    add,
		Code:    200,
	}, nil
}
